<template>
  <div class="Driverfiledetails">
       <el-date-picker
      v-model="year"
      value-format="yyyy"
      type="year"
      placeholder="选择年"
      class="year"
      @change="yearFunc"
    ></el-date-picker>
    <el-table v-bind:data="Ddata" style="width: 100%;margin-top:36px;" v-loading="loading">
      <el-table-column fixed prop="time" label="日期" class="Background#eee"></el-table-column>
      <el-table-column fixed prop="new" label="新增人数" class="Background#eee"></el-table-column>
      <el-table-column prop="cancellation" label="注销人数"></el-table-column>
      <el-table-column fixed="right" label="查看">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="Driverfiledetails(scope.row.sort,1)"
            type="text"
            size="small"
          >新增</el-button>
          <el-button
            @click.native.prevent="Driverfiledetails(scope.row.sort,2)"
            type="text"
            size="small"
          >注销</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      Ddata: [],
      loading: false,
      year:'2019'
    };
  },
  watch: {},
  computed: {},
  methods: {
     yearFunc(val) {
       this.Get()
    },
    // 跳转
    Driverfiledetails(val,number){
      console.log(this.Ddata[val])
      let numberdata = {}
      if(number == 1){
        numberdata.type = this.Ddata[val].add
        numberdata.year = this.year
        numberdata.column= this.Ddata[val].count
      }else if(number == 2){
        numberdata.type = this.Ddata[val].remove
        numberdata.year = this.year
        numberdata.column= this.Ddata[val].count
      }
      
      this.$store.state.count = numberdata
      this.$router.push({path:'/Driverstatisticsdetails'})
    },
    //获取表格数据
    Get() {
      this.loading = true;
      this.$store.dispatch("driver",this.year).then(data => {
        this.loading = false;
        let DriverStatistics = new Array();
        let year = this.year;
        // let a = [];
        // for (var i in data) {
        //   if (data[i].type == 1) {
        //     a.push({
        //       new: data[i].jan,
        //       cancellation: data[i + 1].jan
        //     });
        //   }
        // }
        DriverStatistics.push(
          {
            sort:0,
            id:'1',
            time: year + "-01",
            new: data[0].jan,
            cancellation: data[1].jan,
            add: 1,
            remove: 0,
            count:'jan',
          },
          {
            sort:1,
            time: year + "-02",
            new: data[0].feb,
            cancellation: data[1].feb,
            add: 1,
            remove: 0,
            count:'feb',
          },
          {
            sort:2,
            time: year + "-03",
            new: data[0].mar,
            cancellation: data[1].mar,
            add: 1,
            remove: 0,
            count:'mar',
          },
          {
            sort:3,
            time: year + "-04",
            new: data[0].apr,
            cancellation: data[1].apr,
            add: 1,
            remove: 0,
            count:'apr',
          },
          {
            sort:4,
            time: year + "-05",
            new: data[0].may,
            cancellation: data[1].may,
            add: 1,
            remove: 0,
            count:'may',
          },
          {
            sort:5,
            time: year + "-06",
            new: data[0].jun,
            cancellation: data[1].jun,
            add: 1,
            remove: 0,
            count:'jun',
          },
          {
            sort:6,
            time: year + "-07",
            new: data[0].jul,
            cancellation: data[1].jul,
            add: 1,
            remove: 0,
            count:'jul',
          },
          {
            sort:7,
            time: year + "-08",
            new: data[0].aug,
            cancellation: data[1].aug,
            add: 1,
            remove: 0,
            count:'aug',
          },
          {
            sort:8,
            time: year + "-09",
            new: data[0].sept,
            cancellation: data[1].sept,
            add: 1,
            remove: 0,
            count:'sept',
          },
          {
            sort:9,
            time: year + "-10",
            new: data[0].oct,
            cancellation: data[1].oct,
            add: 1,
            remove: 0,
            count:'oct',
          },
          {
            sort:10,
            time: year + "-11",
            new: data[0].nov,
            cancellation: data[1].nov,
            add: 1,
            remove: 0,
            count:'nov',
          },
          {
            sort:11,
            time: year + "-12",
            new: data[0].dec,
            cancellation: data[1].dec,
            add: 1,
            remove: 0,
            count:'dec',
          }
        );
        this.Ddata = DriverStatistics;
      });
    }
  },
  created() {},
  mounted() {
    this.Get();
    this.$store.commit("SET_USER_INFO", "驾驶员实时统计");
  }
};
</script>
<style>
.el-table_1_column_4 {
  width: 1.5rem;
}
.Driverfiledetails {
  position: fixed;
  top: 0.7rem;
  left: 0;
  overflow-y: scroll;
  width: 100%;
  height: auto;
  -webkit-overflow-scrolling: touch; /*这句是为了滑动更顺畅*/
   bottom: 0;
}
.Driverfiledetails .mint-cell-title {
  text-align: left;
}
</style>